<?php

namespace co2_OS;

use \co2\dev\v0_0_0 as api;

function autoload($class)

{
	if(preg_match('/^co2_OS\\\apps\\\/',$class))
	
	{
		$file=preg_replace('/^co2_OS\\\apps\\\/','',$class);
		
		$file=preg_replace('/\\\/','/',$file);
		
		$file=sysvar::get('apps')."/$file.php";
		
		$file=preg_replace('/v(\d+)_(\d+)_(\d+)/','$1.$2.$3',$file);

		if(!file_exists($file))
		throw new api\Exception('failed to autoload '.$class.' in file '.$file,null,EXIT_STATUS::CLASS_FILE_NOT_FOUND);
		
		require_once $file;
		
		if(!class_exists($class))
		throw new api\Exception('class not found: '.$class.' in file '.$file,null,EXIT_STATUS::CLASS_NOT_FOUND);
	}
}
